from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-01 14:13:12.325669
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 01, Sep, 2021
Time: 14:13:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9292
Nobs: 401.000 HQIC: -46.4707
Log likelihood: 4357.59 FPE: 4.61246e-21
AIC: -46.8256 Det(Omega_mle): 3.69535e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.434762 0.094482 4.602 0.000
L1.Burgenland 0.103601 0.048759 2.125 0.034
L1.Kärnten -0.115345 0.024258 -4.755 0.000
L1.Niederösterreich 0.159161 0.105133 1.514 0.130
L1.Oberösterreich 0.135541 0.103091 1.315 0.189
L1.Salzburg 0.283570 0.051127 5.546 0.000
L1.Steiermark 0.024872 0.067734 0.367 0.713
L1.Tirol 0.109636 0.053544 2.048 0.041
L1.Vorarlberg -0.116672 0.048302 -2.415 0.016
L1.Wien -0.012188 0.093340 -0.131 0.896
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013743 0.219544 0.063 0.950
L1.Burgenland -0.048718 0.113299 -0.430 0.667
L1.Kärnten 0.036405 0.056367 0.646 0.518
L1.Niederösterreich -0.197751 0.244293 -0.809 0.418
L1.Oberösterreich 0.508886 0.239547 2.124 0.034
L1.Salzburg 0.308059 0.118802 2.593 0.010
L1.Steiermark 0.106442 0.157390 0.676 0.499
L1.Tirol 0.314140 0.124417 2.525 0.012
L1.Vorarlberg -0.009916 0.112236 -0.088 0.930
L1.Wien -0.019996 0.216889 -0.092 0.927
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.255273 0.048103 5.307 0.000
L1.Burgenland 0.087670 0.024824 3.532 0.000
L1.Kärnten -0.002456 0.012350 -0.199 0.842
L1.Niederösterreich 0.208296 0.053526 3.892 0.000
L1.Oberösterreich 0.173116 0.052486 3.298 0.001
L1.Salzburg 0.036546 0.026030 1.404 0.160
L1.Steiermark 0.016224 0.034485 0.470 0.638
L1.Tirol 0.062798 0.027260 2.304 0.021
L1.Vorarlberg 0.059404 0.024591 2.416 0.016
L1.Wien 0.104323 0.047521 2.195 0.028
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179846 0.046947 3.831 0.000
L1.Burgenland 0.047054 0.024228 1.942 0.052
L1.Kärnten -0.007149 0.012054 -0.593 0.553
L1.Niederösterreich 0.139092 0.052239 2.663 0.008
L1.Oberösterreich 0.317805 0.051225 6.204 0.000
L1.Salzburg 0.098714 0.025405 3.886 0.000
L1.Steiermark 0.133057 0.033656 3.953 0.000
L1.Tirol 0.076920 0.026605 2.891 0.004
L1.Vorarlberg 0.054454 0.024000 2.269 0.023
L1.Wien -0.040152 0.046379 -0.866 0.387
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209648 0.093648 2.239 0.025
L1.Burgenland -0.059668 0.048329 -1.235 0.217
L1.Kärnten -0.034912 0.024044 -1.452 0.146
L1.Niederösterreich 0.119208 0.104205 1.144 0.253
L1.Oberösterreich 0.177474 0.102181 1.737 0.082
L1.Salzburg 0.257580 0.050676 5.083 0.000
L1.Steiermark 0.078258 0.067136 1.166 0.244
L1.Tirol 0.122439 0.053071 2.307 0.021
L1.Vorarlberg 0.111848 0.047875 2.336 0.019
L1.Wien 0.022365 0.092516 0.242 0.809
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025672 0.072854 0.352 0.725
L1.Burgenland 0.025885 0.037598 0.688 0.491
L1.Kärnten 0.052402 0.018705 2.802 0.005
L1.Niederösterreich 0.213865 0.081067 2.638 0.008
L1.Oberösterreich 0.335333 0.079492 4.218 0.000
L1.Salzburg 0.044742 0.039424 1.135 0.256
L1.Steiermark -0.003208 0.052229 -0.061 0.951
L1.Tirol 0.113157 0.041287 2.741 0.006
L1.Vorarlberg 0.063770 0.037245 1.712 0.087
L1.Wien 0.129304 0.071973 1.797 0.072
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186612 0.088695 2.104 0.035
L1.Burgenland 0.020235 0.045773 0.442 0.658
L1.Kärnten -0.059583 0.022772 -2.616 0.009
L1.Niederösterreich -0.125678 0.098693 -1.273 0.203
L1.Oberösterreich 0.197939 0.096776 2.045 0.041
L1.Salzburg 0.027134 0.047996 0.565 0.572
L1.Steiermark 0.302434 0.063585 4.756 0.000
L1.Tirol 0.490225 0.050264 9.753 0.000
L1.Vorarlberg 0.068517 0.045343 1.511 0.131
L1.Wien -0.104955 0.087622 -1.198 0.231
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161951 0.096669 1.675 0.094
L1.Burgenland -0.005438 0.049888 -0.109 0.913
L1.Kärnten 0.062872 0.024820 2.533 0.011
L1.Niederösterreich 0.196211 0.107567 1.824 0.068
L1.Oberösterreich -0.124635 0.105477 -1.182 0.237
L1.Salzburg 0.241238 0.052311 4.612 0.000
L1.Steiermark 0.154346 0.069302 2.227 0.026
L1.Tirol 0.052574 0.054783 0.960 0.337
L1.Vorarlberg 0.123564 0.049420 2.500 0.012
L1.Wien 0.140275 0.095500 1.469 0.142
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.489052 0.052358 9.340 0.000
L1.Burgenland -0.011119 0.027020 -0.412 0.681
L1.Kärnten -0.010335 0.013443 -0.769 0.442
L1.Niederösterreich 0.203200 0.058261 3.488 0.000
L1.Oberösterreich 0.261633 0.057129 4.580 0.000
L1.Salzburg 0.022465 0.028333 0.793 0.428
L1.Steiermark -0.024192 0.037535 -0.645 0.519
L1.Tirol 0.069977 0.029672 2.358 0.018
L1.Vorarlberg 0.057127 0.026767 2.134 0.033
L1.Wien -0.054938 0.051725 -1.062 0.288
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017509 0.075958 0.136178 0.133418 0.041107 0.067585 -0.000224 0.174029
Kärnten 0.017509 1.000000 -0.056312 0.127306 0.045512 0.070008 0.456720 -0.093687 0.092874
Niederösterreich 0.075958 -0.056312 1.000000 0.281577 0.082934 0.271282 0.015473 0.148703 0.250575
Oberösterreich 0.136178 0.127306 0.281577 1.000000 0.180454 0.287777 0.158541 0.113030 0.136484
Salzburg 0.133418 0.045512 0.082934 0.180454 1.000000 0.128744 0.057736 0.105854 0.050526
Steiermark 0.041107 0.070008 0.271282 0.287777 0.128744 1.000000 0.130312 0.087620 -0.026749
Tirol 0.067585 0.456720 0.015473 0.158541 0.057736 0.130312 1.000000 0.040981 0.116877
Vorarlberg -0.000224 -0.093687 0.148703 0.113030 0.105854 0.087620 0.040981 1.000000 -0.046963
Wien 0.174029 0.092874 0.250575 0.136484 0.050526 -0.026749 0.116877 -0.046963 1.000000